package com.sx.manage.service.system.config;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.sx.manage.service.sys.IMBaseSystemConfigInfoService;
import com.sx.manage.service.sys.IMSystemConfigInfoService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.constants.MSystemConstants;
import com.sx.model.manage.mybatis.form.sys.MSystemConfigInfoForm;
import com.sx.model.manage.mybatis.vo.bank.MDropDownVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;
import com.sx.model.manage.mybatis.vo.sys.MSysConfigVO;

/**
 * 系统参数配置 webService
 * 
 * @author Administrator
 *
 */
@Service("mSystemConfigWebService")
public class MSystemConfigWebService {

	@Resource(name = "mBaseSystemConfigInfoServiceImpl")
	private IMBaseSystemConfigInfoService mBaseSystemConfigInfoServiceImpl;

	@Resource(name = "systemConfigInfoServiceImpl")
	private IMSystemConfigInfoService systemConfigInfoServiceImpl;

	public IMBaseSystemConfigInfoService getmBaseSystemConfigInfoServiceImpl() {
		return mBaseSystemConfigInfoServiceImpl;
	}

	public void setmBaseSystemConfigInfoServiceImpl(IMBaseSystemConfigInfoService mBaseSystemConfigInfoServiceImpl) {
		this.mBaseSystemConfigInfoServiceImpl = mBaseSystemConfigInfoServiceImpl;
	}

	public IMSystemConfigInfoService getSystemConfigInfoServiceImpl() {
		return systemConfigInfoServiceImpl;
	}

	public void setSystemConfigInfoServiceImpl(IMSystemConfigInfoService systemConfigInfoServiceImpl) {
		this.systemConfigInfoServiceImpl = systemConfigInfoServiceImpl;
	}

	/** 跳转到添加界面model **/
	public ViewAndModel toAddViewSystemConfig(ViewAndModel model) {
		ResultObjectVO<MSysConfigVO> result = this.mBaseSystemConfigInfoServiceImpl.get_maxCode();

		model.addObject("systemConfigVO", result.getObjVo());
		model.setViewName("sysSetting/addSys");// 修改ftl页面名称

		model.addObject("type_list", MSystemConstants.configTypeList());
		return model;
	}

	/** 跳转到编辑界面model **/
	public ViewAndModel toEditViewSystemConfig(ViewAndModel model, MSystemConfigInfoForm form) {
		ResultObjectVO<MSysConfigVO> result = this.mBaseSystemConfigInfoServiceImpl.queryByIdSystemConfig(form);
		model.addObject("systemConfigVO", result.getObjVo());
		model.setViewName("sysSetting/editSys");// 修改ftl页面名称
		model.addObject("type_list", MSystemConstants.configTypeList());
		MSysConfigVO configVO = result.getObjVo();
		if (StringUtils.isNotBlank(configVO.getConfig_type())) {
			for (MDropDownVO downVO : MSystemConstants.configTypeList()) {
				if (configVO.getConfig_type().equals(downVO.getId())) {
					model.addObject("type_name", downVO.getText());
				}
			}
		}
		return model;
	}

}
